#ifndef _CFG_H_
#define _CFG_H_
#include <stdint.h>
#include "main.h"
#include "task.h"
#include <string.h>
#include "Queue.h"
#ifdef __cplusplus
extern "C"
{
#endif

#define HARDWARE_VERSION               "V1.0.0"
#define SOFTWARE_VERSION               "V0.1.0"

#define SLEEP_TIME 		        6000/1000				/**睡眠时间**/
/**加热时间任务时间**/
#define HEATING_TASK_TIME       100 
  
/**LED控制**/	
#define LED_L1(status)		LL_GPIO_WritePin(LED_L0_GPIO_Port,LED_L0_Pin,status)
#define LED_L2(status)		LL_GPIO_WritePin(LED_L1_GPIO_Port,LED_L1_Pin,status)
#define LED_L3(status)		LL_GPIO_WritePin(LED_L3_GPIO_Port,LED_L3_Pin,status)
#define LED_L4(status)		LL_GPIO_WritePin(LED_L4_GPIO_Port,LED_L4_Pin,status)
#define LED_L5(status)		LL_GPIO_WritePin(LED_L5_GPIO_Port,LED_L5_Pin,status)
#define LED_L6(status)		LL_GPIO_WritePin(LED_L6_GPIO_Port,LED_L6_Pin,status)
#define LED_L7(status)		LL_GPIO_WritePin(LED_L7_GPIO_Port,LED_L7_Pin,status)
	
#define LED_C1(status)		LL_GPIO_WritePin(LED_C1_GPIO_Port,LED_C1_Pin,status)
#define LED_C2(status)		LL_GPIO_WritePin(LED_C2_GPIO_Port,LED_C2_Pin,status)

#define LED_POWER(status) LL_GPIO_WritePin(LED_D16_GPIO_Port,LED_D16_Pin,status)
#define LED_POWER_FLICKER	LL_GPIO_WritePin(LED_D16_GPIO_Port,LED_D16_Pin)

#define LED_WARM(status)  LL_GPIO_WritePin(LED_D10_GPIO_Port,LED_D10_Pin,status)
#define LED_HEAT(status)  LL_GPIO_WritePin(LED_D13_GPIO_Port,LED_D13_Pin,status)

#define NTC_CHECK				  LL_GPIO_WritePin(ADC_IN1_NTC_GPIO_Port,ADC_IN1_NTC_Pin)

#define HEATING(status)   LL_GPIO_WritePin(HEARINT_GPIO_Port,HEARINT_Pin,status)

#define OPEN 						GPIO_PIN_SET
#define CLOSE						GPIO_PIN_RESET	


/**系统状态**/
typedef enum{
	FULL_SCREEN_DISPLAY,/**全屏显示**/
	RUNNING_DISPLAY,	/**跑马**/
	WORKING_CONDITION,	/**工作状态**/
	OTHER_DISPLAY,		/**其他显示**/
}SWITCH_STATUS;

/**系统信息**/
typedef struct SysInf
{
	/**睡眠时间计时**/
	uint32_t SleepTimeCount;
	/**系统开关状态**/
	uint8_t SwitchStatus;           /**0:关机状态  1：开机状态**/
	/**工作状态**/
	SWITCH_STATUS workingStatus;	
	/**工作状态切换计时**/
	uint8_t SwitchTimeCount;
	/**跑马步骤**/
	uint8_t RunningStep;
	/**运行时间**/
	uint32_t RunningTime;			
	/**运行计时**/
	uint32_t RunningTimeCount;
    /**禁止加热**/
  uint8_t  NoHeatingAllowed;
  
	uint8_t  HeatingStartTime;
	
	uint8_t displayStatus;
	
	uint8_t displayNum;
	uint8_t HeatingWord;
	
	uint8_t lowPower;
} SysInf_s, *SysInf_p;

/**故障信息**/
typedef struct{
	uint8_t BatVoltageLow:1;			/**电池电压低**/
  uint8_t OverCurrent:1;      /**过流**/      
  uint8_t ShortCircuit:1;     /**短路**/
  uint8_t res:5;              /**待定**/
}Fault;

/**温度故障信息**/
typedef union FaultInf{
  Fault bit;                        /**故障位**/
  uint8_t byte;                     /**故障**/
} FaultInf_s,* FaultInf_p;          /**故障信息**/

/**温度饭盒结构体**/
typedef struct TempLunchInf
{
    FaultInf_p fault;
	SysInf_p system;
}TempLunchInf_s;

extern TempLunchInf_s gTempLunchInf;		
		
/**休眠控制**/
extern void SleepOperation(uint8_t sleep);

#include <stdbool.h>

#define BUTTON_POWER_INPUT HAL_GPIO_ReadPin(KEY_ON_GPIO_Port, KEY_ON_Pin) // 电源按键反馈信号


/**********************************ADC数据采集器**************************************************/
#define ADC_CHANNEL_AMOUNT	2//ADC采样通道数量
#define ADC_SAMPLING_NUM    10//ADC采样队列数量

/**数据采集**/
typedef struct 
{
    uint16_t totalADCValue[ADC_SAMPLING_NUM][ADC_CHANNEL_AMOUNT];//ADC采样原始数据缓存数组
    double  filterADCValue[ADC_CHANNEL_AMOUNT];                   //滤波后的ADC采样数据
} ADC_DATA_STR_s;

/****数据缓存****/
typedef struct 
{
    uint32_t dmaADCBuf[ADC_SAMPLING_NUM][ADC_CHANNEL_AMOUNT];//ADC DMA数据缓存空间
    ADC_DATA_STR_s stADC_DATA_STR[1];			 //乒乓buffer
		uint8_t finishFlag;										//完成标志
}ADC_AppData;


/**************************************ADC模拟量处理***********************************************************/
/*ADC 500hz采样频率*/
#define ALPHA_1HZ     (0.01256638)
#define ALPHA_0_5HZ   (0.00628319)

typedef struct
{
	 uint16_t usADVlaue;//AD采样值
	 int32_t i32Value;//AD采样值对应的实际参量(电压，电流等)
}TPoint;

typedef struct
{
	 TPoint   HightPoint;//采样量上限值
	 TPoint   LowPoint;//采样量下限值
	 float    k;
	 float    b;
}TAjustData;

typedef enum
{   
//	ADC_BOARD_TEMP,						    /**饭盒温度**/
    ADC_CONTROL_CURRENT ,			        /**控制电流**/
    ADC_BAT_VOLTAGE,					    /**电池电压**/
}ADCSamplingList;

typedef struct{
	  /*饭盒 temp*/	
//    int32_t i32PCBTemp;				        /**饭盒温度**/
    /*USB QC current*/
    int32_t i32CortrolCurrent;		
    /**电池电压**/
    int32_t i32BatVoltage;
}TADCSamplingData;
extern TADCSamplingData ADCSamplingData;
void SysInit(void);
void ADC_Process(ADC_AppData *pCB);
void DisPlayUI(uint8_t value);
#ifdef __cplusplus
}
#endif

#endif
